/**
 * @description: search-table
 * @date: 2022/4/5
 */

import * as mockjs from 'mockjs';

mockjs.Random.extend({
  phone(start) {
    const prefix = start ? [start] : ['132', '135', '189'];
    return this.pick(prefix) + mockjs.mock(/\d{8}/);
  },
  atime() {
    const randomTime = Math.random() * 1000 * (1000 * 60 * 60 * 24);
    const theTime = new Date().getTime() - randomTime;
    return Math.floor(theTime);
  },
});

const mockApi = [
  {
    url: '/api/search-table',
    method: 'post',
    response: ({ body }) => {
      return {
        code: 0,
        data: body,
      };
    },
  },
  {
    url: '/api/search-table',
    method: 'put',
    response: ({ body }) => {
      return {
        code: 0,
        data: body,
      };
    },
  },
  {
    url: '/api/search-table',
    method: 'get',
    response: ({ query }) => {
      const num = `list|${query.limit || 10}`;
      return {
        code: 0,
        data: mockjs.mock({
          total: 500,
          [num]: [
            {
              id: '@id',
              username: '@cname',
              username_en: '@name',
              'sex|1': ['1', '2'], // 1-male, 2-female
              'experience|1': ['1','3','5','10','10+'], // 工作经验
              describe: '@cword(10, 50)',
              hobby: '@cword(2, 10)',
              phone: `@phone(${query.search})`,
              address: '@county(true)',
              'status|1': query.jobStatus ? [query.jobStatus] : ['1', '2'], // 就职状态
              lastTime: '@atime',
              createTime: '@atime',
            },
          ],
        }),
      };
    },
  },
  {
    url: '/api/search-table/detail',
    method: 'get',
    response: ({ query }) => {
      return {
        code: 0,
        data: mockjs.mock({
          id: query.id,
          username: '@cname',
          describe: '@cword(10, 50)',
          phone: '@phone',
          address: '@county(true)',
          'status|1': ['1', '2'], // 就职状态
          lastTime: '@atime',
          createTime: '@atime',
        }),
      };
    },
  },
  {
    url: '/api/search-table',
    method: 'delete',
    response: ({ query }) => {
      return {
        code: 0,
        data: query,
      };
    },
  },
];

export default mockApi;
